Repository navigation
UI: TextureRenderCore's drawBitmapFaceWithBlendUnk at 100% - #494
Merged
Merged
Conversation
Rewritten from the binary. gynt's draft a5ef761 (sourcehold reimpl/TextureRenderCore, 87.1% there, 87.4% on main) was the starting point; its per-channel grouping and the signed division by 32 are kept. - Both loops are plain for loops over the face's 66 rows and 64 columns, as in drawBitmapFace. MSVC unrolls the RGB565 one by four itself, which gives the original's four pixels per iteration and its channel order. - In the RGB565 loop the surface pointer steps in both branches of the colour-key test, as the original steps it after every pixel. With one step behind the test, the unrolled copies write through offsets instead. - The RGB555 blend has one local per channel: as one expression, the RGB565 loop computes red before green. - The RGB555 path weighs the face by the strength, not 32 - strength, and leaves out the surface, as the original does; it is marked fixme. - The masks are main's ColorChannelMask constants. Narrow build with drawBitmapFace (100% on main): 100.0 raw and normalised, the original's 409 instructions. It needs no /GL line. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gynt
approved these changes
Nov 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One function at 100%, rewritten from the binary. No header changes, no
/GLline.TextureRenderCore::drawBitmapFaceWithBlendUnkgynt's draft is a5ef761 (2026-10-04, "reimplement: SHC_3BB0A8C1_0x0044CEB0 87.1% ushort pixel locals, per-channel grouping and signed division by 0x20") on sourcehold's reimpl/TextureRenderCore. Its per-channel grouping and the signed division by 32 are kept here; the rest is written again in the shape of
drawBitmapFace(0x0044CD40, on main), which draws the same face without blending.Measured
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), and sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie. The struct resolvers and the function resolvers are enabled locally (not committed).drawBitmapFace.cpp(its one callee, 100% on main), on main 1f87a13: 100.0 raw and normalised. The whole listing is the same as the original's 409 instructions.drawBitmapFacestays at 100.0. With this file on the/GLlist it also reads 100.0, so the PR adds no/GLline./GLlist, and withrequestGoods(0x004D1F00) andMenuItemActionHandler_Allies_Main(0x004B12D0) left out with their resolvers off (they still use the twoPlayerDatafields Reimplement 29 Synchrony and Game functions at 100% #403 renames), together withhasEnoughGoldForMoat(0x0040CAC0), which doesn't compile on main until Reimplement 88 Map::TileMapState functions at 100% #366 (its header returnsBOOLEnumsince the Reimplement 88 Map::TileMapState functions at 100% #366 sync, the fileuint): 0 failed of 2,655 compile steps, 99.68 over 2,671 functions.drawBitmapFaceWithBlendUnkreads 100.0 raw and normalised there, with no diff entry, and every other function reads exactly what it reads in the same build of main (unrounded 99.6839 raw and 99.6456 normalised, 2,563 functions at 100.0 raw; main alone: 99.6838 and 99.6455 over 2,670, 2,562 at 100.0).What the function does
It draws one 64 x 66 face bitmap at a position, blended by a strength from 0 to 32. A strength of 0 draws the face plainly through
drawBitmapFace, and 32 draws nothing. It draws on the surface thatdrawBufferChoiceValuepicks, asdrawBitmapFacedoes, and skips the magenta colour key. In RGB565 each channel is the face's weighted by 32 - strength plus the surface pixel's weighted by the strength, out of 32. In RGB555 the face's weight is the strength itself, the reverse of RGB565, and the surface under it is left out: a strength of 1 draws the face almost black and 31 almost unchanged. The code does what the original does and marks itfixme.For the maintainers: the RGB555 weight looks like a bug in the original (inverted against the RGB565 path). It is kept, since the function matches the binary.
What got it to 100%
Each of these was measured against the form it names:
forloops over the 66 rows and 64 columns. MSVC unrolls the RGB565 loop by four itself. That gives the original's four pixels per iteration, with the face read at[ebx]to[ebx+6]and oneadd ebx, 8. It also gives the original's channel order, green before red: with the four pixels written out by hand, as in the draft, every pixel computes red first, whatever order the source writes the channels in (the draft reads 87.4%).++pixelbehind the test, the unrolled copies write through[ecx+2],[ecx+4]and[ecx+6]and step it by 8 instead (86.8%). The RGB555 loop is not unrolled and has the single step ofdrawBitmapFace(the same listing either way).faceWeightbefore the surface switch, where the original computes32 - strength(0x0044CEF6). Declared inside the RGB565 branch, where it is used, it reads 94.6 / 79.4.Checker items (not changed)
surface,rowSkipandlineByteWidthare set in each arm of the surface switch and read after it.rowSkipandlineByteWidthare declared the same way indrawBitmapFace.surfaceis a local here because this original keeps the surface in a register and stores the global once after the switch (0x0044CF5B), wheredrawBitmapFacestores the global in each arm.Proposed, not changed here
colorOrBlendOrGammaUnkis a blend strength from 0 to 32 in this function: 0 draws the face plainly, 32 draws nothing, and the RGB565 path weighs the surface by it. Proposed name:blendStrengthUnk, as main'srenderGMWithBlending,renderTgxWithColorAndBlendingUnkandRenderCurrentButtonToScreenMenuWithBlendingUnkcall theirs.drawBitmapFace; as in UI: TextureRenderCore's moveOverlappingMenuPartsToMapSurface at 100% #476's and UI: TextureRenderCore's renderUnitAnimationWithBlendingUnk at 100% #480's texts, aVC_MAP_SURFACE_WIDTHconstant would name it.Other PRs
🤖 Generated with Claude Code